
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
'''
@Project ：图灵学习 
@File    ：1.csv数据存储.py
@IDE     ：PyCharm 
@Author  ：ChenLiGao
@Date    ：2024-11-29 10:25
'''
import csv

headers = ['班级', '姓名', '性别', '手机号', 'QQ']

rows = [
    ["18级Python", '小王', '男', '13146060xx1', '123456xx1'],
    ["18级Python", '小李', '男', '13146060xx2', '123456xx2'],
    ["19级Python", '小赵', '女', '13146060xx3', '123456xx3'],
    ["19级Python", '小红', '女', '13146060xx4', '123456xx4'],
]

# newline=‘’ 让windows去除空格行
with open("1test.csv", 'w', newline='') as f:
    # 创建一个csv写入对象
    fcsv = csv.writer(f)

    fcsv.writerow(headers) # 写入表头
    fcsv.writerows(rows) # 写入数据